package com.ssy.lingxi.message.websocket;

import com.ssy.lingxi.component.rabbitMQ.constants.MessageConstants;
import com.ssy.lingxi.component.rabbitMQ.service.IRabbitMQUtils;
import com.ssy.lingxi.message.websocket.model.WsMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;

/**
 * webSocket消息服务
 * 将消息投递到消息队列中, 各个消费端监听并消费, 解决集群websocket问题
 * @author yzc
 * @version 2.0.0
 * @date 2020/10/27
 */
@Slf4j
@Service
public class WsMessagePushService {

    @Resource
    private IRabbitMQUtils rabbitMQUtils;

    /**
     * 推送消息
     */
    public void pushMessage(WsMessage wsMessage) {
        this.pushMessageList(Collections.singletonList(wsMessage));
    }

    /**
     * 批量推送消息
     */
    public void pushMessageList(List<WsMessage> wsMessage) {
        // 推入消息队列
        rabbitMQUtils.sendMsg(MessageConstants.ws_deliver_message_exchange, wsMessage);
    }
}
